package com.example.framework;

import java.util.Collection;
import java.util.HashSet;
import java.util.Set;

import com.example.objects.ContactObject;

public class Contacts {
	
	private Set<ContactObject> storedContacts = null;
	
	public Contacts(Collection<ContactObject> list) {
		storedContacts = new HashSet<ContactObject>(list);		
	}

	public Contacts withAdded(ContactObject contact) {		
		Contacts contacts2 = new Contacts(storedContacts);
		contacts2.storedContacts.add(contact);
		return contacts2;
	}
	
	public Contacts without(ContactObject contact) {		
		Contacts contacts2 = new Contacts(storedContacts);
		contacts2.storedContacts.remove(contact);
		return contacts2;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result
				+ ((storedContacts == null) ? 0 : storedContacts.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Contacts other = (Contacts) obj;
		if (storedContacts == null) {
			if (other.storedContacts != null)
				return false;
		} else if (!storedContacts.equals(other.storedContacts))
			return false;
		return true;
	}

	public int size() {
		return storedContacts.size();
	}

	@Override
	public String toString() {
		return "Contacts [storedContacts=" + storedContacts + "]";
	}
	
	public ContactObject getSomeContact() {
		return storedContacts.iterator().next();
	}

}

